<?php

namespace models;

use system\Model;

class BaseModel extends Model {
    protected $logName = '';

    /**
     * 记录日志
     *
     * @param int    $action 动作 1,2,3
     * @param int    $uid
     * @param string $find
     *
     * @throws
     */
    public function recordLog($action = 1, $uid = 1, $find = '') {
        $model = new Logs();
        $data  = [
            'title' => $this->logName . '--' . $this->getAction($action),
            'extra' => is_array($find) ? json_encode($find) : '',
            'uid'   => $uid,
        ];
        $model->create($data);
        $model->insert();
    }

    /**
     * 获取操作
     *
     * @param string $action
     *
     * @return mixed
     */
    protected function getAction($action = 'add') {
        $actions = [
            1 => '添加',
            2 => '更新',
            3 => '删除',
        ];

        return $actions[ $action ];
    }

	/**
	 * 处理数据
	 * @param array $data
	 * @return bool|void
	 * @author Colin <amcolin@126.com>
	 * @date 2021-12-20 下午2:18
	 */
    protected function afterFind(&$data){
		if (isset($data['create_time'])){
			$data['create_time'] = timeFormat($data['create_time']);
		}
	}
}
